var ui = window.ui||{
		success:function(message,error){
			var style = (error==1)?"html_clew_box clew_error ":"html_clew_box";
			var html   =   '<div class="" id="ui_messageBox" style="display:none">'
						   + '<div class="html_clew_box_close"><a href="javascript:void(0)" onclick="$( \'#ui_messageBox\' ).fadeOut(\'fast\',function(){jQuery(\'.boxy-modal-blackout\').remove();});" title="关闭"></a></div>'
						   + '<div class="html_clew_box_con" id="ui_messageContent">&nbsp;</div></div>';
			var init      =  0;
			
			var showMessage = function( message ){		
				if( !init ){
					$('body').append( html );
					init = 1;
				}
				
	
				
				$( '#ui_messageContent' ).html( message );
				$('#ui_messageBox').attr('class',style);
				
				var v =  ui.box._viewport() ;
				
				jQuery('<div class="boxy-modal-blackout"></div>')
		        .css(jQuery.extend(ui.box._cssForOverlay(), {
		            zIndex: 99, opacity: 0.2
		        })).appendTo(document.body);
				
				
				$( '#ui_messageBox' ).css({
					left:( v.left + v.width/2  - $( '#ui_messageBox' ).outerWidth()/2 ) + "px",
					top:(  v.top  + v.height/2 - $( '#ui_messageBox' ).outerHeight()/2 ) + "px"
				});		
				
				$( '.html_clew_box_close' ).css({
					left:($( '#ui_messageBox' ).outerWidth()-21 ) + "px"
				});		
				
				$( '#ui_messageBox' ).fadeIn("slow");
			}
			
			
			var closeMessage = function(){
				setTimeout( function(){  
					$( '#ui_messageBox' ).fadeOut("fast",function(){
						jQuery('.boxy-modal-blackout').remove(); 
					});
				} , 2000);
			}
			
			showMessage( message );
			closeMessage();
	
		},
		
		error:function(message){
			ui.success(message,1);
		},
	
		load:function(){
			var init = 0
			var loadingBox = '<div class="html_clew_box" id="ui_loading" style="display:none"><div class="html_clew_box_con"><span class="ico_waiting">加载中……</span></div></div>';
			if( !init ){
				$('body').append( loadingBox );
				init = 1;
			}
			
			$( '#ui_loading' ).css({
				right:100+"px",
				top:($(document).scrollTop())+"px"
			});
			$( '#ui_loading' ).fadeIn("slow");
		},
		
		loaded:function(){
			var loadingBox = '#ui_loading';
			$( loadingBox ).fadeOut("slow");
		},
		
		quicklogin:function(){
			ui.box.load( quickloginpath ,{title:'快速登录'});
		},
		
		confirm:function(o,text){
			var callback = $(o).attr('callback');
			text = text || '确定要做此项操作吗？';
			this.html = '<div id="ts_ui_confirm" class="Prompt_confirm"><span class="txt"></span><br><span style=""><input type="button" value="确定"  class="btn_o">&nbsp;&nbsp;<input type="button" value="取消"  class="btn_w"></span></div>';
			if( $('#ts_ui_confirm').html()==null ){
				$('body').append(this.html);
			}
			var position = $(o).offset();
			
			$("#ts_ui_confirm .txt").html(text);
			var tmp_left = position.left-($("#ts_ui_confirm").width()/2);
			if(tmp_left<20)tmp_left=20;
			$('#ts_ui_confirm').css({"top":position.top+"px","left":tmp_left+"px","display":"none"});
			
			$('#ts_ui_confirm').fadeIn("fast");
			$("#ts_ui_confirm .btn_w").one('click',function(){
				$('#ts_ui_confirm').fadeOut("fast");
				$("#ts_ui_confirm .btn_o").unbind("click");
			});
			$("#ts_ui_confirm .btn_o").one('click',function(){
				$('#ts_ui_confirm').fadeOut("fast");
				eval(callback);
			});
		},
		
		card:function(o){
			$('#q_ui_card').fadeOut("fast");
			var user_id = $(o).attr('uid');
			var curl = $(o).attr('curl');
			var alert_info = '<div style="text-align: center;margin:20px auto;"><img src="/Public/Images/global/loading.gif"><span style="font-size:14px;color:#000000">&nbsp;数据加在中...</span></div>';
			this.html = '<table style="position:absolute;height:1px; z-index:9;display:none;" " id="q_ui_card" cellspacing="0" cellpadding="0" border="0" class="boxy-wrapper" >'
		        				+'<tbody>'
		        					+'<tr>'
			        					+'<td class="boxy-top-left"></td>'
			        					+'<td class="boxy-top"></td>'
			        					+'<td class="boxy-top-right"></td>'
			        				+'</tr>'
			        				+'<tr>'
				        				+'<td class="boxy-left"></td>'
				        				+'<td class="boxy-inner">'
				        				+'	<div style="position:relative; height:0; width:100%;"><div class="q_ico_arrow" style="left:49%;"></div></div>'
				        				+'	<div id="uc_show_area" style="width:330px;height: 165px; overflow: hidden;"></div>'
				        				+'</td>'
				        				
				        				+'<td class="boxy-right"></td>'
			        				+'</tr>'
			        				+'<tr>'
				        				+'<td class="boxy-bottom-left"></td>'
				        				+'<td class="boxy-bottom"></td>'
				        				+'<td class="boxy-bottom-right"></td>'
			        				+'</tr>'
			        			+'</tbody>'
			        		+'</table>';
			if( $('#q_ui_rcard').html()==null ){
				$('body').append(this.html);
				$("#q_ui_card").hover(function(){},function(){$('#q_ui_card').fadeOut("fast");});
			}else{
				//$('#q_ui_card').fadeOut("fast");
			}
			
			var position = $(o).offset();
			
			$("#q_ui_card").find("#uc_show_area").html(alert_info);
			$.kajax({      
				url:curl,      
				type:'post', //数据发送方式  
				data:{ user_id:user_id } ,    
				async: false ,//同步方式     
				success: function(html){ 
					$("#q_ui_card").find("#uc_show_area").html(html);
				}
			});
			$('#q_ui_card').css({"top":position.top+($(o).height()+5)+"px","left":position.left-($("#q_ui_card").width()/2 - $(o).width()/2)+"px","display":"none"});
			
			$('#q_ui_card').fadeIn("fast");
		}
	};


//扩展ajax方法。
//$(function(){
	$.extend({
	　　kajax:function(options) {
				//alert("call kajax!");
				var defaults = {
					ajx_rtn_type:'HTML',//HTML JSON
					type:"post",
					url:'',
					data:{},
					async:true,
					dataType:"html",
					success:null,//如果为json则将解析好的json对象作为参数调用success。
					error:null
					};
				var error_fun = options.error;
				var success_fun = options.success;
				var opts=$.extend(defaults,options);
				if(opts.type=="post"||opts.type=="POST")opts.data=$.extend(opts.data,{ajx_rtn_type:opts.ajx_rtn_type});//将返回数据格式添加到请求参数中
				if(opts.type=="get"||opts.type=="GET")opts.url=opts.url+"/"+ajx_rtn_type+"/"+opts.ajx_rtn_type;//将返回数据格式添加到请求参数中
				
				opts.error = function(rtndata){
					if(error_fun!=null)error_fun(rtndata);
				};
				
				opts.success = function(rtndata){
					//alert(rtndata);
					if(opts.ajx_rtn_type=='JSON'){
						var obj	=	eval('(' + rtndata + ')');
					    if(obj.status==-99){
					    	ui.box.close();
					    	ui.quicklogin();
					    }else{
					    	if(success_fun!=null)success_fun(obj);
					    }

					}else{
						if(success_fun!=null)success_fun(rtndata);
					}
				};
				$.ajax(opts);
		}

	});
//});


function AutoResizeImage(maxWidth,maxHeight,objImg){
	var img = new Image();
	img.src = objImg.src;
	var hRatio;
	var wRatio;
	var Ratio = 1;
	var w = img.width;
	var h = img.height;
	wRatio = maxWidth / w;
	hRatio = maxHeight / h;
	if (maxWidth ==0 && maxHeight==0){
		Ratio = 1;
	}else if (maxWidth==0){//
		if (hRatio<1) Ratio = hRatio;
	}else if (maxHeight==0){
		if (wRatio<1) Ratio = wRatio;
	}else if (wRatio<1 || hRatio<1){
		Ratio = (wRatio<=hRatio?wRatio:hRatio);
	}
	if (Ratio<1){
		w = w * Ratio;
		h = h * Ratio;
	}
	objImg.height = h;
	objImg.width = w;
}

//模拟ts U函数
function U(url,params){
	var website = _ROOT_+'/index.php';
	url = url.split('/');
	if(url[0]=='' || url[0]=='@') url[0] = APPNAME;
	website = website+'?app='+url[0]+'&mod='+url[1]+'&act='+url[2];
	if(params){
		params = params.join('&');
		website = website + '&' + params;
	}
	return website;
}



// 图片缩放
function photo_resize(name,sizeNum){
	var newWidth = $(name).width();
    $(name +" img").each(function(){
        
        var width = sizeNum || 728;
        var images = $(this);
        
        //判断是否是IE
        if (-[1, ]) {
            image = new Image();
            image.src = $(this).attr('src');
            image.onload = function(){
                if (image.width >= width) {
                    images.click(function(){
                        tb_show("", this.src, false);
                    });
                    images.width(width);
                    images.height(width / image.width * image.height);
                }
            }
        }
        else {
            if (images.width() >= width) {
                images.click(function(){
                    tb_show("", this.src, false);
                });
                images.width(width);
                images.height(width / images.width() * images.height());
            }
        }

		
		//image.attr('rel','imageGroup');

    });
}


function checkFormItems(formid){
	var form=jQuery("#"+formid);
	var elements = form.find(':input[require]');

	var isValid = true;
	var errIndex= new Array();
	var n=0;
	elements.each(function(i){
		if(validator.check(jQuery(this))==false){
			isValid  = false;
			errIndex[n++]=i;
		};
	});

	if(isValid==false){
		elements.eq(errIndex[0]).focus().select();
		return false;
	}
	return true;
}

function changeverify(){
	//alert('changeverify');
    var date = new Date();
    var ttime = date.getTime();
    var url = KURLDATA.changeverify;
    $('#verifyimg').attr('src',url+'?test='+ttime);
}
